﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bot;
using Intorise.Common;
using System.Threading;

namespace 挂机BOSS之家强化石
{
    public partial class Form1 : MainWindow
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// BOSS之家小怪挂机脚本
        /// </summary>
        protected override void RunScript()
        {
        进入BOSS之家:
            ConsoleBLL.WriteLineInfo("进入BOSS之家...");
            int count = 0;
            FlashKeyPress(Keys.Escape);
            FlashLeftClick(830, 110, 1000);
            FlashLeftClick(467, 181);
            FlashLeftClick(588, 261);
            FlashLeftClick(555, 565);

            DateTime begin;
            Bitmap Img_BOSS之家 = (Bitmap)Image.FromFile(ImageRoot + "\\Location\\BOSS之家.bmp");
            begin = DateTime.Now;
            while (true)
            {
                Thread.Sleep(5000);
                CaptureCurrentImage();
                var point = ImageTools.SearchImage(currentImage, Img_BOSS之家, new Rectangle(986, 20, 60, 30));
                if (point != Point.Empty)
                {
                    ConsoleBLL.WriteLineInfo("已进入boss之家...");
                    break;
                }
                if ((DateTime.Now - begin) > timeout)
                {

                    if (count < 3)
                    {
                        ConsoleBLL.WriteLineError("进入BOSS之家超时...重试...");
                        count++;
                        goto 进入BOSS之家;
                    }
                    ConsoleBLL.WriteLineError("进入BOSS之家超时3次...退出脚本");
                    return;
                }
            }

            FlashKeyPress(Keys.M);
            FlashLeftClick(405, 523);
            FlashKeyPress(Keys.M);

            using (Bitmap Img_BOSS之家挂小怪坐标 = (Bitmap)Image.FromFile(ImageRoot + "\\Location\\BOSS之家挂小怪坐标.bmp"))
            {
                begin = DateTime.Now;
                while (true)
                {
                    if ((DateTime.Now - begin).TotalSeconds > 90)
                    {
                        ConsoleBLL.WriteLineError("进入BOSS之家挂机地点超时...退出脚本");
                        return;
                    }
                    CaptureCurrentImage();
                    var point = ImageTools.SearchImage(currentImage, Img_BOSS之家挂小怪坐标, new Rectangle(986, 20, 60, 30));
                    if (point != Point.Empty)
                    {
                        break;
                    }
                    Thread.Sleep(3000);
                    FlashKeyPress(Keys.M);
                    FlashLeftClick(405, 523);
                    FlashKeyPress(Keys.M);
                }


                ConsoleBLL.WriteLineInfo("已到达挂机地点，开始挂机...");
                Guid fenjieID = Guid.NewGuid();//分解任务编号
                Guid captureID = Guid.NewGuid();//按钮点击任务编号
                Guid locationID = Guid.NewGuid();//回挂机地点任务编号

                Hide界面();
                AutoFight();

                while (!quit)
                {
                    Thread.Sleep(3000);//3秒钟检测一次
                    BotHelper.TimespanRun(Fenjie, 10 * 60 * 1000, fenjieID);//定时10分钟分解
                    BotHelper.TimespanRun(() =>
                    {
                        CaptureCurrentImage();
                        if (CheckDisconnect())
                        {
                            ConsoleBLL.WriteLineWaring("已断线，退出脚本...");
                            quit = true; return;
                        }
                        var point = ImageTools.SearchImage(currentImage, Img_BOSS之家, new Rectangle(986, 20, 60, 30));
                        if (point == Point.Empty)
                        {
                            ConsoleBLL.WriteLineInfo("当前地图不是boss之家...退出脚本"); return;
                        }
                        //死亡检测
                        Process立即使用();
                        Process完成任务();
                    }, 3 * 60 * 1000, captureID);//定时3分钟扫描图像

                    BotHelper.TimespanRun(() =>
                    {
                        ConsoleBLL.WriteLineWaring("回到挂机指定地点...");
                        FlashKeyPress(Keys.M);
                        FlashLeftClick(405, 510);
                        FlashKeyPress(Keys.M);
                        AutoFight();
                    }, 1 * 60 * 1000, locationID);//定时1分钟回到挂机指定地点

                }//end while
            }
        }
    }
}
